//2009/08/13 19:48:55
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class MedalTable
{
public:
    vector <string> generate(vector <string> results)
    {
        vector<pair<pair<int, int>, pair<int, string> > > v;
        v.clear();
        for (int i=0; i<results.size(); i++)
        {
            stringstream s(results[i]);
            string s1, s2, s3;
            s >> s1 >> s2 >> s3;
            bool flag1 = true;
            bool flag2 = true;
            bool flag3 = true;
            for (int j=0; j<v.size(); j++)
            {
                if (v[j].second.second == s1)
                {
                    v[j].first.first --;
                    flag1 = false;
                }
            }
            if (flag1) v.push_back(make_pair(make_pair(-1,0), make_pair(0, s1)));
            for (int j=0; j<v.size(); j++)
            {
                if (v[j].second.second == s2)
                {
                    v[j].first.second --;
                    flag2 = false;
                }
            }
            if (flag2) v.push_back(make_pair(make_pair(0,-1), make_pair(0, s2)));
            for (int j=0; j<v.size(); j++)
            {
                if (v[j].second.second == s3)
                {
                    v[j].second.first --;
                    flag3 = false;
                }
            }
            if (flag3) v.push_back(make_pair(make_pair(0,0), make_pair(-1, s3)));
        }
        sort(v.begin(), v.end());
        vector<string> ret;
        for (int i=0; i<v.size(); i++)
        {
            stringstream ss;
            ss << v[i].second.second << " " << -v[i].first.first << " " << -v[i].first.second << " " << -v[i].second.first;
            ret.push_back(ss.str());
        }
        return ret;
    }
};
